<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>封装</title>
</head>

<body>
    <script>
        function getnum(arr) {
            let arr1 = []
            let j = 0, num = 0
            for (let i = 0; i < arr.length; i++) {
                if (arr[i] < 20) {
                    arr1[j] = arr[i]
                    j++
                } else {
                    num += arr[i]
                }
            }
            arr1.sort(function (a, b) {
                return a - b
            })
            console.log(`大于20的累加和为：${num}`);
            return arr1
        }
        let arr2 = getnum([1, 4, 5, 9, 7, 8, 6, 21, 11, 34, 56, 78])
        console.log(arr2)
        for (let i = 0; i < arr2.length; i++) {
            console.log(arr2[i])
        }
    </script>
</body>

</html>